package com.huli.controller;

import com.huli.pojo.NursingProject;
import com.huli.service.NursingProjectService;
import com.huli.util.Result;
import com.huli.vo.OrganizationUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/nursingProject")
public class NursingProjectController {
    // 自动注入NursingProjectService
    @Autowired
    private NursingProjectService nursingProjectService;


    // 处理/nursingProjectList请求，返回OrganizationUserVo对象
    @RequestMapping("/nursingProjectList")
    public OrganizationUserVo nursingProjectList(OrganizationUserVo organizationUserVo){
        // 调用nursingProjectService的nursingProjectList方法，传入organizationUserVo对象，返回OrganizationUserVo对象
        return nursingProjectService.nursingProjectList(organizationUserVo);
    }


    // 修改护理项目数据
    @RequestMapping("/updateNursingProject")
    public Result updateNursingProject(NursingProject nursingProject){
        try {
            // 调用nursingProjectService的updateNursingProject方法，传入nursingProject对象
            nursingProjectService.updateNursingProject(nursingProject);
            // 返回修改护理项目成功的结果
            return Result.success("修改护理项目成功");
        } catch (Exception e) {
            // 打印异常信息
            e.printStackTrace();
            // 返回修改护理项目失败的结果
            return Result.error("修改护理项目失败");
        }
    }

    // 添加护理项目数据
    @RequestMapping("/addNursingProject")
    public Result addNursingProject(NursingProject nursingProject){
        try {
            // 调用nursingProjectService的addNursingProject方法，传入nursingProject对象
            nursingProjectService.addNursingProject(nursingProject);
            // 返回添加护理项目成功的结果
            return Result.success("添加护理项目成功");
        }catch (Exception e){
            // 打印异常信息
            e.printStackTrace();
            // 返回添加护理项目失败的结果
            return Result.error("添加护理项目失败");
        }
    }
    @RequestMapping("/selectNursingProjectById")
    public Result selectNursingProjectById(Long id){
        try {
            // 调用nursingProjectService的selectNursingProjectById方法，传入id，返回Result对象
             NursingProject nursingProjectList = nursingProjectService.selectNursingProjectById(id);
             return Result.success("查询护理项目成功",nursingProjectList);
        }catch (Exception e){
            // 打印异常信息
            e.printStackTrace();
            // 返回查询护理项目失败的结果
            return Result.error("查询护理项目失败");
        }
    }
    @RequestMapping("/findAll")
    public Result findAll(){
        try {
            // 调用nursingProjectService的findAll方法，返回Result对象
            List<NursingProject> nursingProjectList = nursingProjectService.findAll();
            return Result.success("查询护理项目成功",nursingProjectList);
        }catch (Exception e){
            // 打印异常信息
            e.printStackTrace();
            // 返回查询护理项目失败的结果
            return Result.error("查询护理项目失败");
        }
    }
}